<template>
  <div>
    <template>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="余额" width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.walletBalance + '元' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="账户状态" width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px" v-if="scope.row.walletState == 0">正常</span>
            <span style="margin-left: 10px" v-if="scope.row.walletState == 1">异常</span>
            <span style="margin-left: 10px" v-if="scope.row.walletState == 2">冻结</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="openDrawer(scope.row.walletId)" type="primary" style="margin-left: 16px;">可用优惠券
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-drawer title="可用优惠券" :visible.sync="drawer" :with-header="false">
      <!--      <span>我来啦!</span>-->
      <template>
        <el-table :data="discount" style="width: 100%">
          <el-table-column prop="discountInfo" label="可用优惠券" width="180"></el-table-column>
        </el-table>
      </template>
    </el-drawer>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import { getInfo } from '@/api/login'
import { selectDiscountInfo, selectWalletInfo } from '@/api/driver/driver'

export default {
  //import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    //这里存放数据"

    return {
      walletId: '',
      tableData: [],
      discount: [],
      drawer: false
    }
  },
  //计算属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    getInfo() {
      getInfo().then(res => {
        this.walletId = res.data.user.userId
        selectWalletInfo(this.walletId).then(res => {
          this.tableData = res.data
        })
      })
    },
    openDrawer(walletId) {
      this.drawer = true
      //console.log(walletId)
      selectDiscountInfo(walletId).then(res => {
        // console.log(res)
        this.discount = res.data
      })
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.getInfo()
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
}
</script>
<style scoped>

</style>
